package com.example.rxjavautildemo.fragment.rxbus;

import com.example.rxjavautildemo.base.base.BaseRxBusTestFragment;
import com.example.rxjavautildemo.entity.Event;
import com.example.rxjavautildemo.entity.EventKey;
import com.xuexiang.rxutil2.rxbus.RxBusUtils;

import io.reactivex.functions.Consumer;

public class RxBusTestFragment3 extends BaseRxBusTestFragment {
    @Override
    protected void initViews() {
        super.initViews();
        setBackgroundColor(android.R.color.holo_orange_light);
    }

    @Override
    protected void initListener() {
        super.initListener();
        RxBusUtils.get().onMainThread(EventKey.EVENT_BACK_MAINTHREAD, String.class, new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                showContent(EventKey.EVENT_BACK_MAINTHREAD, "   EventName:" + s + ", 当前线程状态： " + Event.getLooperStatus());
            }
        });
        RxBusUtils.get().onMainThread(EventKey.EVENT_BACK_NORMAL, String.class, new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                final String msg = "事件Key:" + EventKey.EVENT_BACK_NORMAL + "\n   EventName:" + s + ", 当前线程状态： " + Event.getLooperStatus();
                showContent(msg);
            }
        });
    }

    @Override
    protected void onCancelEvent() {
        RxBusUtils.get().unregisterAll(EventKey.EVENT_BACK_NORMAL);
        RxBusUtils.get().unregisterAll(EventKey.EVENT_BACK_NORMAL);
        RxBusUtils.get().unregister(EventKey.EVENT_CLEAR,mSubscribeInfo);

    }
}
